package com.linxchong.security.filter;

import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimitUtils;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.support.DefaultRateLimitKeyGenerator;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:linchong
 * @CreateTime:2020-07-15 13:01
 * @Description:自定义限流策略
 */
@Component
public class MyKeyGen extends DefaultRateLimitKeyGenerator {

	public MyKeyGen(RateLimitProperties properties, RateLimitUtils rateLimitUtils) {
		super(properties, rateLimitUtils);
	}

	/**
	 * 自定义限流key生成策略，根据key做限流
	 * @param request
	 * @param route
	 * @param policy
	 * @return
	 */
	@Override
	public String key(HttpServletRequest request, Route route, RateLimitProperties.Policy policy) {
		return super.key(request, route, policy);
	}
}
